home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1338 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.5 KB  |  62 lines

  1. Path: urals.jpl.nasa.gov!user
  2. From: mlj@tazboy.jpl.nasa.gov (Mose L. Johnson)
  3. Newsgroups: comp.lang.c++,comp.sys.mac.programmer.help,comp.sys.mac.oop.misc,comp.sys.mac.oop.tcl
  4. Subject: [Q] Overloading operator ->
  5. Date: Tue, 09 Jan 1996 08:54:36 -0800
  6. Organization: Jet Propulsion Laboratory
  7. Message-ID: <mlj-0901960854360001@urals.jpl.nasa.gov>
  8. NNTP-Posting-Host: urals.jpl.nasa.gov
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=US-ASCII
  11. Content-Transfer-Encoding: 7bit
  12.  
  13. I am making a small interface for debuging prposes.  The set of classes should
  14. allow the source to remain as close to its original form as possible.  One
  15. of the things I am working on is Memory Management.
  16.  
  17. One of the things I want to do is overload the arrow(->) operator.  Here
  18. is an example of what I tried and want to do.
  19.  
  20. ---
  21.  
  22. template <class T> class ref<class T>
  23. {
  24.    public:
  25.    T* operator ->();
  26. };
  27.  
  28. class tester
  29. {
  30.    public:
  31.    void member();
  32. };
  33.  
  34. void main()
  35. {
  36.    ref<tester *> var;
  37.  
  38.    var->member();
  39. }
  40.  
  41. ---
  42.  
  43. When I try to compile this, my compiler gives me an error of:
  44.    illegal return type for operator->()
  45.  
  46. If I declare that function as:
  47.    ref<T *>* operator ->();
  48.  
  49. it compiles, but my compiler returns an error of:
  50.    member() is not a member of ref<tester *>
  51.  
  52. How do I get 'ref<T*>::operator ->()' to return a pointer to class T.
  53.  
  54. I am using Symantec C++ 7.0 on a Macintosh to compile my code.
  55.  
  56. Your help will be welcomed.  I need to have the interface by this weeks
  57. end.  You can send a reply to me at:
  58.   mlj@tazboy.jpl.nasa.gov
  59.  
  60.  
  61.       Thanks in advance Mose L. Johnson.
  62.